<?php
	require_once( "functions/inc_systemFunctions.php" );
	page_header( "Wayne Schlegel Inc. | Shopping list", true, "myflight" );
?>

<?php 
	$sql = "SELECT    product.id AS product_id, 
	                  product.marketingName AS product_marketingName, 
	                  product.slotInShelf AS product_slotInShelf,
	                  shelfs.shelf_floor AS shelfs_floor, 
	                  shelfs.shelf_corridor AS shelfs_corridor,
	                  shoppingListItems.seenInStore AS seenInStore
	        FROM      shoppingListItems 
	        JOIN      product 
	        ON        shoppingListItems.Product_id = product.id 
	        JOIN      shelfs 
	        ON        product.tbl_shelfs_id = shelfs.shelf_ID 
	        WHERE     shoppingListItems.shoppingList_id = " . getShoppingListId( $_SESSION['user_id'] ) . " ";
	if( empty( $_GET['shw'] ) ) {
		$sql .= " AND shoppingListItems.seenInStore = 0 ";
	}
 
	$sql.= "ORDER BY  shelfs.shelf_floor, shelfs.shelf_corridor, product.slotInShelf";
	
	$res = mysql_query( $sql );
	echo "<table class=\"iTable\">";
	if( $res ){
		$cnt = 0;
		while( $row = mysql_fetch_array( $res ) ){
			$cnt++;
			echo "<tr class=\"moreInformation";
			if( !empty( $_GET['pid'] ) && $_GET['pid'] == $currentProduct['id'] ){
				echo " newItem";
			}
			if( $cnt == mysql_num_rows( $res ) ){
				echo " lastItem";
			}
			echo "\">";
			if( $row['seenInStore'] == 0 ){
				echo "<td style=\"background-image: none; width: 40px;\"><a href=\"shoppingListItemToggle.php?pid=" . $row['product_id'] . "\"><img src=\"/images/icons/seenNo.png\" /></a></td>";
			} else {
				echo "<td style=\"width: 40px;\"><a href=\"shoppingListItemToggle.php?pid=" . $row['product_id'] . "\"><img src=\"/images/icons/seenYes.png\" /></a></td>";
			}
			echo "<td><a href=\"product-details.php?pid=" . $row['product_id'] . "&nextProduct=\">" . $row['product_marketingName'] . "</a></td></tr>";
		}
	} else {
		echo "<tr class=\"lastItem\"><td>no product on your shopping-list</td></tr>";
	}
	echo "</table>";
	
?>

<table class="iTable">
	<tr class="moreInformation lastItem">
		<td>
			<?php
				if( !empty( $_GET['shw'] ) && $_GET['shw'] == "all" ){
				?>
				<a href="shopping-list.php?shw=">show only unsighted items</a>
				<?php
				} else {
				?>
				<a href="shopping-list.php?shw=all">show all items</a>
				<?php
				}
				?>
		</td>
	</tr>
</table>

<?php
	page_footer();
?>